﻿using A.M.ETO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using W.M.Materiel.Application.IServices;
using W.M.Materiel.Application.Services;
using W.M.Materiel.Domain.Entity;
using W.M.Materiel.Infrastruecure.Repository;

namespace W.M.Materiel.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Bom_list_propertiesController : ControllerBase
    {
        private readonly IBom_list_propertiesServices bom_List_PropertiesServices;

        public Bom_list_propertiesController(IBom_list_propertiesServices bom_List_PropertiesServices)
        {
            this.bom_List_PropertiesServices = bom_List_PropertiesServices;
        }

        /// <summary>
        /// 显示物料属性分页+查询
        /// </summary>
        /// <param name="pageSize">页容量</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="name">查询条件:物料属性名称</param>
        /// <returns>统一返回格式</returns>
        [HttpGet]
        public async Task<IActionResult> GetBom_list_properties(int pageSize, int pageIndex, string? name)
        {
            var list = await bom_List_PropertiesServices.GetBom_list_properties(pageSize,pageIndex,name);
            return Ok(list);
        }

        /// <summary>
        /// 显示物料属性信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetBom_List_Categories()
        {
            var res =await bom_List_PropertiesServices.GetBom_List_Categories();
            return Ok(res);
        }

        /// <summary>
        /// 添加物料属性
        /// </summary>
        /// <param name="c">物料属性实体</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> GetBom_list_propertiesAdd(bom_list_properties c)
        {
            var list =await bom_List_PropertiesServices.GetBom_list_propertiesAdd(c);
            return Ok(list);
        }

        /// <summary>
        /// 删除物料属性实体
        /// </summary>
        /// <param name="c">物料属性编号</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> GetBom_list_propertiesDel(string? c)
        {
            var list =await bom_List_PropertiesServices.GetBom_list_propertiesDel(c);
            return Ok(list);
        }

        /// <summary>
        /// 修改物料属性信息
        /// </summary>
        /// <param name="c">物料属性实体</param>
        /// <returns>统一返回格式</returns>
        [HttpPost]
        public async Task<IActionResult> GetBom_list_propertiesUpdate(bom_list_properties c)
        {
            var list =await bom_List_PropertiesServices.GetBom_list_propertiesUpdate(c);
            return Ok(list);
        }

        /// <summary>
        /// 反填物料属性
        /// </summary>
        /// <param name="material_attribute_number">物料属性编号</param>
        /// <returns>物料属性信息</returns>
        [HttpGet]
        public async Task<IActionResult> GetbackfillProperties(string? material_attribute_number)
        {
            var list=await bom_List_PropertiesServices.GetbackfillProperties(material_attribute_number);
            return Ok(list);
        }

        /// <summary>
        /// 物料属性导出
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> PropertiesExportTiExcel()
        {
            var list =await bom_List_PropertiesServices.GetShowInforAsync();
            var steram = new MemoryStream();
            steram.SaveAs(list);
            steram.Seek(0, SeekOrigin.Begin);
            return new FileStreamResult(steram, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "物料属性信息.xlsx"
            };
        }
    }
}
